package moodish.server;


import java.util.LinkedList;
/**
 * The client of moodish network. The client have a nickname and his list of friends
 * 
 * @author Goncalo, Ana, Bruno
 *
 */
public class Client {
	
	private String nickname;
	private boolean isConnected = false;
	private LinkedList<String> listOfFriends; 
	
	/**
	 * Constructor, it construct a new Client and create an empty list of his friends
	 * @param nickname  The Nickname of the Client
	 */
	public Client(String nickname){
		this.nickname=nickname; 
		listOfFriends = new LinkedList<String>();
	}
	/**
	 * Get the Nickname from the Client
	 * @return nickname
	 */
	public String getClient() {
		return nickname;
	}
	
    /**
	 * set client as connected
	 */
	public void setConnected() {
		 isConnected = true;
		
	}
	/**
	 * @return true if a client  is currently connected
	 * @return false if the client is disconnected
	 */
	public boolean isConnected() {
		
		return isConnected;
	}
	/**
	 * set client as disconnected
	 */
	public void setDisconnected() {
		isConnected = false;
		
	}
	/**
	 * Removes all friends from the list 
	 */
	public void removeAllFriends(){
		listOfFriends.clear();
	}
	/**
	 * Get the client list of friends 
	 * @return the list of friends
	 */
    public LinkedList<String> getFriends(){
    	return listOfFriends;
    }
	/**
	 * Checks if the nickname is not in the list of friends
	 * @param payload  nickname of the user to check
	 * @return true if the client is not already a friend
	 * @return false if the client is already a friend
	 */
	public boolean IsFriend(String payload) {
		for(String f : listOfFriends){
			if(f.equals(payload))
			return true;	
		}
		return false;
	}
	/**
	 * Add a new friend to the client list of friends
	 * @param payload   nickname to add to the list
	 */
	public void addFriend(String payload) {
		listOfFriends.add(payload);
		
	}
	/**
	 * Remove a friend of the client list of friends
	 * @param payload   nickname to remove from the list
	 */
	public void removeFriend(String payload) {
		listOfFriends.remove(payload);
		
	}
	
    public String toString(){
    	return nickname;
    }
}
